package com.hotel.payment.mq;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.hotel.payment.config.RabbitConfig.ORDER_CREATED_QUEUE;
import static com.hotel.payment.config.RabbitConfig.PAYMENT_EVENT_EXCHANGE;

@Component
public class PaymentSuccessListener {

    @Autowired
    private AmqpTemplate amqpTemplate;

    @RabbitListener(queues = ORDER_CREATED_QUEUE)
    public void onOrderCreated(Long orderId) {
        // 模拟异步支付完成，发送 payment.success 事件
        amqpTemplate.convertAndSend(PAYMENT_EVENT_EXCHANGE, "payment.success", orderId);
    }
}
